package Homework;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

//客户端1
public class Client1 {

	public static void main(String[] args) {
		//创建客户端套接字
		Socket socket=null;
		DataInputStream dis=null;
		DataOutputStream dos =null;
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		
		try {
			socket = new Socket("127.0.0.1", 9990);
			System.out.println("客户端1已启动。。。。。。");
			//创建输入输出流
			dis = new DataInputStream(socket.getInputStream());
			dos = new DataOutputStream(socket.getOutputStream());
			
			//先向服务器发送请求
			System.out.print("请输入账户名：");
			String accountName=scanner.next();
			System.out.print("请输入账户密码：");
			String accountPwd=scanner.next();
			//将请求传送给服务器
			dos.writeUTF("账户名："+accountName+"---密码："+accountPwd);
			String infoFromServer = dis.readUTF();
			System.out.println("服务器说："+infoFromServer);
			while(true) {
				//循环发送请求和读取服务器发来的反馈
				System.out.print("客户端1对服务器说：");
				String info=scanner.next();
				dos.writeUTF(info);
				String infoFrom = dis.readUTF();
				System.out.println("服务器说："+infoFrom);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				dis.close();
				dos.close();
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
